<html>
<head>
	<style type="text/css">
		.b{
			width: 600px;
		
		}
		.c{
			margin:10px;
			border:1px solid red;
		
		}
	
	</style>
	<script type="text/javascript">
		var inputsBox = new Array();
		var i = 0;

		function calculaMedia(){
			var soma = 0;
			var x=0;
			while(x<inputsBox.length){
				soma = soma + eval(document.getElementById("inpt"+x).value);
				x++;
			}
			soma = (soma/x);
			alert(soma);
		}
		function remove(button){
			var str=button.id; 
			var n=str.replace("bt","");
			var input = document.getElementById("inpt"+n);
			var label = document.getElementById("lbl"+n);
			
			document.getElementById("mydiv").removeChild(button);
			document.getElementById("mydiv").removeChild(input);
			document.getElementById("mydiv").removeChild(label);
			
			
			
		}
		function showText(button){
			var str=button.id; 
			var n=str.replace("bt","");
			var input = document.getElementById("inpt"+n);
			alert(input.value);
			
		}
		function addInput() {
			var labelText = document.createTextNode("Texto "+i+" : ");
			var label = document.createElement("label");
			var button = document.createElement("input");
			var input = document.createElement("input");
			var br = document.createElement("br");
			
			label.setAttribute("id","lbl"+i);
			label.appendChild(labelText);
			
			input.setAttribute("type", "text");
			input.setAttribute("id", "inpt"+i);
			input.setAttribute("class", "c");
			
			button.setAttribute("type", "button");
			button.setAttribute("id", "bt"+i);
			button.setAttribute("value","Exibir Texto");
			button.setAttribute("onclick","remove(this)")
			
			document.getElementById("mydiv").appendChild(label);
			document.getElementById("mydiv").appendChild(input);
			document.getElementById("mydiv").appendChild(button);
			document.getElementById("mydiv").appendChild(br);
			inputsBox[i] = input;
			i++;
		}
	</script>
		<body>
			<div class="b" id="mydiv"></div>
			<input  type="button" onclick="addInput()" value="AddInputBox" />
			<input  type="button" onclick="calculaMedia()" value="Media" />
		</body>
</html>

